import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description: 牛客网.中等题.栈的压入弹出序列
 */
public class Test {
    public static boolean IsPopOrder(int [] pushA,int [] popA) {
        Stack<Integer> stack = new Stack<>();
        int j = 0;
        for (int i = 0; i < pushA.length; i++) {
            stack.push(pushA[i]);
            while(!stack.empty() && j < popA.length && stack.peek() == popA[j]) {
                stack.pop();
                j++;
            }
        }
        if(j < popA.length) {
            return false;
        }
        return true;
    }

    public static void main(String[] args) {
        int[] pushA = new int[]{1,2,3,4,5};
        int[] popA = new int[]{4,5,3,2,1};
        boolean f = IsPopOrder(pushA,popA);
        System.out.println(f);
    }
}
